package com.zues.samples.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonBackReference;

@Entity
@Table(name = "exam_score")
public class Score implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5881973375806554746L;

	@Id
	@GeneratedValue
	@Column(name = "id", nullable = false, length = 11)
	private Integer id;

	@Column(name = "user_id", length = 10, nullable = false,insertable = false, updatable = false)
	private String userId;

	@Column(name = "subject_id", length = 11, nullable = false,insertable = false, updatable = false)
	private Integer subjectId;

	@Column(name = "exam_time", nullable = false)
	private Date examTime;

	@Column(name = "score", nullable = false)
	private BigDecimal score;

	@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST })
	@JoinColumn(name = "user_id")
	private User user;

	@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST })
	@JoinColumn(name = "subject_id")
	private Subject subject;

	public Score() {
		super();
	}

	public Score(Integer id, String userId, Integer subjectId, Date examTime, BigDecimal score, User user,
			Subject subject) {
		super();
		this.id = id;
		this.userId = userId;
		this.subjectId = subjectId;
		this.examTime = examTime;
		this.score = score;
		this.user = user;
		this.subject = subject;
	}

	public User getUser() {
		return user;
	}

	@JsonBackReference
	public void setUser(User user) {
		this.user = user;
	}

	public Subject getSubject() {
		return subject;
	}

	@JsonBackReference
	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public Integer getSubjectId() {
		return subjectId;
	}

	public void setSubjectId(Integer subjectId) {
		this.subjectId = subjectId;
	}

	public Date getExamTime() {
		return examTime;
	}

	public void setExamTime(Date examTime) {
		this.examTime = examTime;
	}

	public BigDecimal getScore() {
		return score;
	}

	public void setScore(BigDecimal score) {
		this.score = score;
	}

	@Override
	public String toString() {
		return "Score [id=" + id + ", userId=" + userId + ", subjectId=" + subjectId + ", examTime=" + examTime
				+ ", score=" + score + ", user=" + user + ", subject=" + subject + "]";
	}

	
}
